package com.crm.miaohe.mapper;

import com.crm.miaohe.model.TblPriceStrategyItem;
import com.crm.miaohe.model.TblPriceStrategyItemExample;

import java.time.LocalDateTime;
import java.util.List;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.ResultMap;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.SelectKey;
import org.apache.ibatis.annotations.Update;

@Mapper
public interface TblPriceStrategyItemMapper {
    long countByExample(TblPriceStrategyItemExample example);

    int deleteByExample(TblPriceStrategyItemExample example);

    @Delete({
        "delete from tbl_price_strategy_item",
        "where id = #{id,jdbcType=BIGINT}"
    })
    int deleteByPrimaryKey(Long id);

    @Insert({
        "insert into tbl_price_strategy_item (strategy_id, category_code, ",
        "category_name, product_code, ",
        "product_name, spec_code, ",
        "spec_name, price, ",
        "create_time, create_user, ",
        "update_time, update_user, ",
        "version)",
        "values (#{strategyId,jdbcType=BIGINT}, #{categoryCode,jdbcType=VARCHAR}, ",
        "#{categoryName,jdbcType=VARCHAR}, #{productCode,jdbcType=VARCHAR}, ",
        "#{productName,jdbcType=VARCHAR}, #{specCode,jdbcType=VARCHAR}, ",
        "#{specName,jdbcType=VARCHAR}, #{price,jdbcType=BIGINT}, ",
        "#{createTime,jdbcType=TIMESTAMP}, #{createUser,jdbcType=VARCHAR}, ",
        "#{updateTime,jdbcType=TIMESTAMP}, #{updateUser,jdbcType=VARCHAR}, ",
        "#{spec_num,jdbcType=BIGINT},", "#{spec_num,jdbcType=BIGINT})"
    })
    @SelectKey(statement="SELECT LAST_INSERT_ID()", keyProperty="id", before=false, resultType=Long.class)
    int insert(TblPriceStrategyItem record);

    int insertSelective(TblPriceStrategyItem record);

    /**
     * 批量插入
     * @param list
     * @return
     */
    int insertBatch(List<TblPriceStrategyItem> list);

    List<TblPriceStrategyItem> selectByExample(TblPriceStrategyItemExample example);

    @Select({
        "select",
        "id, strategy_id, category_code, category_name, product_code, product_name, spec_code, ",
        "spec_name, price, create_time, create_user, update_time, update_user, version,spec_num",
        "from tbl_price_strategy_item",
        "where id = #{id,jdbcType=BIGINT}"
    })
    @ResultMap("com.crm.miaohe.mapper.TblPriceStrategyItemMapper.BaseResultMap")
    TblPriceStrategyItem selectByPrimaryKey(Long id);

    @Select({
            "select",
            "distinct product_code, product_name, category_code, category_name, spec_code, spec_name",
            "from tbl_price_strategy_item"
    })
    List<TblPriceStrategyItem> selectProductCodeAndCategoryCode();

    int updateByExampleSelective(@Param("record") TblPriceStrategyItem record, @Param("example") TblPriceStrategyItemExample example);

    void updateMoq(List<Long> strategyIds, String categoryCode, String productCode, long moqTimes, long moq, String updateUser, LocalDateTime updateTime);

    void updateStopSell(List<Long> strategyIds, String categoryCode, String productCode, boolean stopSell, String updateUser, LocalDateTime updateTime);

    int updateByExample(@Param("record") TblPriceStrategyItem record, @Param("example") TblPriceStrategyItemExample example);

    int updateByPrimaryKeySelective(TblPriceStrategyItem record);

    @Update({
        "update tbl_price_strategy_item",
        "set strategy_id = #{strategyId,jdbcType=BIGINT},",
          "category_code = #{categoryCode,jdbcType=VARCHAR},",
          "category_name = #{categoryName,jdbcType=VARCHAR},",
          "product_code = #{productCode,jdbcType=VARCHAR},",
          "product_name = #{productName,jdbcType=VARCHAR},",
          "spec_code = #{specCode,jdbcType=VARCHAR},",
          "spec_name = #{specName,jdbcType=VARCHAR},",
          "price = #{price,jdbcType=BIGINT},",
          "create_time = #{createTime,jdbcType=TIMESTAMP},",
          "create_user = #{createUser,jdbcType=VARCHAR},",
          "update_time = #{updateTime,jdbcType=TIMESTAMP},",
          "update_user = #{updateUser,jdbcType=VARCHAR},",
          "version = #{version,jdbcType=BIGINT}",
            "spec_num = #{spec_num,jdbcType=BIGINT}",
        "where id = #{id,jdbcType=BIGINT}"
    })
    int updateByPrimaryKey(TblPriceStrategyItem record);
}
